<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/interna.xhtml">
	<ui:define name="nav">
		<h:form id="menu">
			<p:menu id="menuItens" styleClass="menu">
				<p:menuitem value="Cadastro" url="/admin/marca/cadastro" />						
			</p:menu>
		</h:form>
	</ui:define>

	<ui:define name="centro">

		<h2 class="titulo-admin">Cadastro de marcas</h2>

		<p:separator id="separator" styleClass="separador" />		
		
		<p:messages id="messages" 
			    showDetail="true" 
			    autoUpdate="true"
				showSummary="false"/>	
		
		<h:form id="formMarca">		

			<h:panelGrid columns="2" cellspacing="10">				

					<h:outputLabel value="Nome" />
					<p:inputText value="#{marcaManagedBean.marca.nome}"
						id="nome" 
						required="true"
						requiredMessage="Nome deve ser informado"
						size="35">
						<f:validateLength for="nome" minimum="1" />
					</p:inputText>

					<h:outputLabel value="Web site" />
					<p:inputText value="#{marcaManagedBean.marca.webSite}"
						id="webSite" 
						required="true"
						requiredMessage="Web site deve ser informado"
						size="35">
						<f:validateLength for="webSite" minimum="5" />
					</p:inputText>		
					
					<p:commandButton value="Incluir"
						actionListener="#{marcaManagedBean.salvar()}"
						update="formMarca :formMarcas:marcas"
						process="@this, nome, webSite"/>			

			</h:panelGrid>		
					
		</h:form>
		
		<h2 class="titulo-admin">Lista de marcas</h2>

		<p:separator id="separator2" styleClass="separador" />	
		
		<h:form id="formMarcas">			
			
			<p:contextMenu for="marcas">  
        		<p:menuitem value="Editar" update=":formAtualiza:display" icon="ui-icon-pencil" oncomplete="dlg.show()" process="@this,marcas"/>  
        		<p:menuitem value="Excluir" update="marcas" icon="ui-icon-close" actionListener="#{marcaManagedBean.excluir()}"/>  
    		</p:contextMenu>			
			
			<p:dataTable id="marcas" 
				var="marca" 
			    value="#{marcaManagedBean.marcas}"
			    rowKey="#{marca.id}"
				paginator="true" rows="30"	
				selection="#{marcaManagedBean.marcaSelecionada}"	
				selectionMode="single"	
				style="width:80%"										
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
				
				<p:column headerText="Nome" style="width:45%">					
					<h:outputText value="#{marca.nome}"/>  			
				</p:column>
				
				<p:column headerText="Web site" style="width:45%">					
					<h:outputText value="#{marca.webSite}"/>  				
				</p:column>
				
				<p:column headerText="Ativo" style="width:10%">					
					<h:outputText value="Sim" rendered="#{marca.ativo}"/>
					<h:outputText value="N&atilde;o" rendered="#{!marca.ativo}" style="color:red"/>			
				</p:column>
							
			</p:dataTable>	
			
		</h:form>	
		
		<h:form id="formAtualiza">
			<p:dialog header="Atualiza&ccedil;&atilde;o" 
			widgetVar="dlg" 
			resizable="false" 
			showEffect="clip" 
			hideEffect="explode"			
			id="dialogo">   			  
  
        		<h:panelGrid columns="2" cellspacing="10" id="display">  
        		
            		<h:outputLabel value="Nome" />
					<p:inputText value="#{marcaManagedBean.marcaSelecionada.nome}"
						id="unome" 
						required="true"
						requiredMessage="Nome deve ser informado"
						size="35">
						<f:validateLength for="unome" minimum="3" />
					</p:inputText>

					<h:outputLabel value="Web site" />
					<p:inputText value="#{marcaManagedBean.marcaSelecionada.webSite}"
						id="uwebSite" 
						required="true"
						requiredMessage="Web site deve ser informado"
						size="35">
						<f:validateLength for="uwebSite" minimum="5" />
					</p:inputText>	
					
					<h:outputText value="Ativo " rendered="#{!marcaManagedBean.marcaSelecionada.ativo}"/>  
        			<p:selectOneMenu id="uativo" 
        			value="#{marcaManagedBean.marcaSelecionada.ativo}"
        			rendered="#{!marcaManagedBean.marcaSelecionada.ativo}" style="width:53px">
        			    <f:selectItem itemLabel="Sim" itemValue="true"/>        				       			           			     			            			
        			</p:selectOneMenu>				
					
					<p:commandButton value="Atualizar"
						actionListener="#{marcaManagedBean.atualizar()}"
						oncomplete="dlg.hide();"
						update=":formMarcas:marcas"/>					
					 
        		</h:panelGrid>       		
     
			</p:dialog>			
		
		</h:form>					
		
	</ui:define>
</ui:composition>
</html>